package com.example.studentapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.studentapp.R;
import com.example.studentapp.beans.CourseList;
import com.example.studentapp.course.CourseEditActivity;

import java.util.List;

public class CourseListAdapter extends BaseAdapter {
    Context context;
    List<CourseList> list;
    public CourseListAdapter(Context context,List<CourseList> list){
        this.context = context;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_course,null);
        TextView item_course_nameTV = view.findViewById(R.id.item_course_nameTV);
        item_course_nameTV.setText(list.get(i).getName());
        ImageView moreIV = view.findViewById(R.id.moreIV);
        moreIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, CourseEditActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("course_id",list.get(i).getId());
                intent.putExtra("course_name",list.get(i).getName());
                context.startActivity(intent);
            }
        });
        return view;
    }
}
